const path = require('path');
const { name } = require('./package');

function resolve(dir) {
  return path.join(__dirname, dir);
}


var NODE_ENV = process.env.NODE_ENV

const port = 31785; // dev port

var publicPath = `//localhost:${port}`

// 项目名称
var proejctName = 'web-microApp-module-vue2';
var ossUrl = 'https://gstor-default-workspace-cn-shanghai-c218770b.oss-accelerate.aliyuncs.com';
var ossPath = `${ossUrl}/${proejctName}/dist/`;

// 生产
if(NODE_ENV == 'production'){
  publicPath = ossPath
}

module.exports = {
  /**
   * You will need to set publicPath if you plan to deploy your site under a sub path,
   * for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/,
   * then publicPath should be set to "/bar/".
   * In most cases please use '/' !!!
   * Detail: https://cli.vuejs.org/config/#publicpath
   */
  publicPath: publicPath,
  outputDir: 'dist',
  assetsDir: 'static',
  filenameHashing: true,
  // tweak internal webpack configuration.
  // see https://github.com/vuejs/vue-cli/blob/dev/docs/webpack.md
  devServer: {
    // host: '0.0.0.0',
    hot: true,
    disableHostCheck: true,
    port,
    overlay: {
      warnings: false,
      errors: true,
    },
    headers: {
      'Access-Control-Allow-Origin': '*',
    },
  },
  // 自定义webpack配置
  configureWebpack: {
    resolve: {
      alias: {
        '@': resolve('src'),
      },
    },
    output: {
      // 把子应用打包成 umd 库格式
      library: `${name}-[name]`,
      libraryTarget: 'umd',
      jsonpFunction: `webpackJsonp_${name}`,
    },
    // 拆共用包
    externals: {
      jquery: 'jQuery',
      immutable: 'Immutable',
      lodash: '_',
      'rxjs-compat': 'rxjs',
      'bignumber.js': 'BigNumber',
      'whatwg-fetch': 'WHATWGFetch',
      eventProxy: 'EventProxy',
      storejs: 'store',
    },
  },
};
